
package com.dynamixsoftware;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public final class UEH {

	private static String app_package;
	private static String app_version;
	private static File data_path;
	private static char[] esc_char = new char[] {
			'\"', '\\', '/', '\b', '\f', '\n', '\r', '\t'
	};
	private static char[] esc_char_z = new char[] {
			'\"', '\\', '/', 'b', 'f', 'n', 'r', 't'
	};
	private static String model;
	private static long project_id;
	private static byte[] reserve_memory;
	private static Thread st;
	private static String version;

	private static void appendData(StringBuffer var0, String var1, String var2) {
		var0.append(var1);
		var0.append(":\"");
		if (var2 != null) {
			char[] var6 = new char[var2.length()];
			var2.getChars(0, var2.length(), var6, 0);
			int var7 = 0;

			for (int var8 = 0; var8 < var6.length; ++var8) {
				int var10 = -1;

				for (int var11 = 0; var11 < esc_char.length; ++var11) {
					if (var6[var8] == esc_char[var11]) {
						var10 = var11;
						break;
					}
				}

				if (var10 != -1) {
					var0.append(var6, var7, var8 - var7);
					var0.append('\\');
					var0.append(esc_char_z[var10]);
					var7 = var8 + 1;
				}
			}

			var0.append(var6, var7, var6.length - var7);
		}

		var0.append("\"");
	}

	private static void get_reserve_memory() {
		if (reserve_memory == null) {
		}
		try {
			reserve_memory = new byte[32768];
			return;
		} catch (OutOfMemoryError localOutOfMemoryError) {
		}
	}

	public static void init(android.content.Context paramContext, long paramLong) {
	}

	private static void release_reserve_memory() {
		if (reserve_memory != null) {
			reserve_memory = null;
			System.gc();
		}
	}

	public static void reportThrowable(Throwable paramThrowable) {
		reportThrowable(false, paramThrowable, null);
	}

	public static void reportThrowable(Throwable paramThrowable, String paramString) {
		reportThrowable(false, paramThrowable, paramString);
	}

	private static void reportThrowable(boolean paramBoolean, Throwable paramThrowable, String paramString) {

		try {
			release_reserve_memory();
			try {
				StringBuffer localStringBuffer1 = new StringBuffer(4096);
				localStringBuffer1.append("{");
				localStringBuffer1.append("protocol_version:1");
				localStringBuffer1.append(",");
				localStringBuffer1.append("date:").append(System.currentTimeMillis());
				localStringBuffer1.append(",");
				appendData(localStringBuffer1, "version", version);
				localStringBuffer1.append(",");
				appendData(localStringBuffer1, "model", model);
				localStringBuffer1.append(",");
				appendData(localStringBuffer1, "package_name", app_package);
				localStringBuffer1.append(",");
				appendData(localStringBuffer1, "package_version", app_version);
				localStringBuffer1.append(",");
				StringBuffer localStringBuffer2 = localStringBuffer1.append("force_close:");
				int i = 1;
				localStringBuffer2.append(i);
				localStringBuffer1.append(",");
				localStringBuffer1.append("exceptions:[");
				int j = 1;
				if (j == 0) {
					localStringBuffer1.append(",");
				}
				localStringBuffer1.append("{");
				appendData(localStringBuffer1, "name", paramThrowable.getClass().getName());
				localStringBuffer1.append(",");
				appendData(localStringBuffer1, "message", paramThrowable.getMessage());
				localStringBuffer1.append(",stacktrace:[");
				StackTraceElement[] arrayOfStackTraceElement = paramThrowable.getStackTrace();
				int k = 0;
				if (k < arrayOfStackTraceElement.length) {
					if (k > 0) {
						localStringBuffer1.append(",");
					}
					localStringBuffer1.append("{");
					appendData(localStringBuffer1, "class_name", arrayOfStackTraceElement[k].getClassName());
					localStringBuffer1.append(",");
					appendData(localStringBuffer1, "method_name", arrayOfStackTraceElement[k].getMethodName());
					localStringBuffer1.append(",");
					appendData(localStringBuffer1, "file_name", arrayOfStackTraceElement[k].getFileName());
					localStringBuffer1.append(",");
					localStringBuffer1.append("line_number:").append(arrayOfStackTraceElement[k].getLineNumber());
					localStringBuffer1.append("}");
					k++;
				}
				localStringBuffer1.append("]}");
				paramThrowable = paramThrowable.getCause();
				j = 0;
				if (paramThrowable != null) {
				}
				localStringBuffer1.append("]");
				if (paramString != null) {
					localStringBuffer1.append(",");
					appendData(localStringBuffer1, "info", paramString);
				}
				localStringBuffer1.append("}");
				saveReport(localStringBuffer1.toString());
			} catch (Throwable localThrowable) {
				localThrowable.printStackTrace();
			}
			synchronized (st) {
				st.notifyAll();
				get_reserve_memory();
				return;
			}
		} finally {
		}
	}

	private static void saveReport(String var0) {
		try {
			if (!data_path.exists()) {
				data_path.mkdirs();
			}

			String var2 = Integer.toHexString(var0.hashCode());
			File var3 = new File(data_path, var2 + ".tmp");
			File var4 = new File(data_path, var2 + ".dat");
			BufferedOutputStream var5 = new BufferedOutputStream(new FileOutputStream(var3), 4096);
			var5.write("project_id=".getBytes());
			var5.write(String.valueOf(project_id).getBytes());
			var5.write("&data=".getBytes());
			var5.write(URLEncoder.encode(var0).getBytes());
			var5.close();
			var3.renameTo(var4);
		} catch (IOException var6) {
			var6.printStackTrace();
		}
	}

	private static boolean sendReport(File paramFile) {
		HttpURLConnection localHttpURLConnection;
		try {
			do {
				try {
					localHttpURLConnection = (HttpURLConnection) new URL(
							"http://ueh.dynamixsoftware.com/errors/report.ashx").openConnection();
					localHttpURLConnection.setConnectTimeout(5000);
					localHttpURLConnection.setReadTimeout(5000);
					localHttpURLConnection.setDoOutput(true);
					localHttpURLConnection.setRequestMethod("POST");
					localHttpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
					OutputStream localOutputStream = localHttpURLConnection.getOutputStream();
					BufferedInputStream localBufferedInputStream = new BufferedInputStream(new FileInputStream(
							paramFile), 4096);
					byte[] arrayOfByte = new byte[4096];
					int i = localBufferedInputStream.read(arrayOfByte);
					if (i < 0) {
						break;
					}
					localOutputStream.write(arrayOfByte, 0, i);
					localBufferedInputStream.close();
				} catch (IOException localIOException) {
					localIOException.printStackTrace();
					return false;
				}
			} while (localHttpURLConnection.getResponseCode() != 200);
		} catch (IOException e) {
			e.printStackTrace();
		}
		paramFile.delete();
		return true;
	}
}
